/**
 * 
 */
package com.toncen.samepms.common;

import java.io.File;
import java.io.IOException;
import java.net.URL;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;

import com.opensymphony.xwork2.config.providers.XmlConfigurationProvider;
import com.sky.common.file.FileUtils;

/**
 * 自定义自动加载Struts配置文件
 * 
 * @author tch
 * 
 */
public class CustomStrutsConfigurationProvider extends XmlConfigurationProvider {

	private static final String FILE_SUFFIX = ".struts.xml";

	public CustomStrutsConfigurationProvider() {
		Map<String, String> mappings = new HashMap<String, String>();
		mappings.put("-//OpenSymphony Group//XWork 2.1.3//EN", "xwork-2.1.3.dtd");
		mappings.put("-//OpenSymphony Group//XWork 2.1//EN", "xwork-2.1.dtd");
		mappings.put("-//OpenSymphony Group//XWork 2.0//EN", "xwork-2.0.dtd");
		mappings.put("-//OpenSymphony Group//XWork 1.1.1//EN", "xwork-1.1.1.dtd");
		mappings.put("-//OpenSymphony Group//XWork 1.1//EN", "xwork-1.1.dtd");
		mappings.put("-//OpenSymphony Group//XWork 1.0//EN", "xwork-1.0.dtd");
		mappings.put("-//Apache Software Foundation//DTD Struts Configuration 2.0//EN", "struts-2.0.dtd");
		mappings.put("-//Apache Software Foundation//DTD Struts Configuration 2.1//EN", "struts-2.1.dtd");
		mappings.put("-//Apache Software Foundation//DTD Struts Configuration 2.1.7//EN", "struts-2.1.7.dtd");
		setDtdMappings(mappings);
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see com.opensymphony.xwork2.config.ContainerProvider#needsReload()
	 */
	// @Override
	// public boolean needsReload() {
	// return true;
	// }
	/*
	 * (non-Javadoc)
	 * 
	 * @see com.opensymphony.xwork2.config.providers.XmlConfigurationProvider#getConfigurationUrls(java.lang.String)
	 */
	@Override
	protected Iterator<URL> getConfigurationUrls(String fileName) throws IOException {
		List<URL> urls = new ArrayList<URL>();
		List<File> files = FileUtils.getAllFile(new File(FileUtils.getClassPath()), FILE_SUFFIX);
		for (File file : files) {
			urls.add(file.toURI().toURL());
		}
		return urls.iterator();
	}

}
